﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration;
using Driver;
using Driver.Const;
using Driver.Features;
using SupportLibrary;
using Automation.Protocols.Model;
using Common.Logging;



namespace AutomationTest
{
    public class Program
    {
        private static ILog log = LogManager.GetLogger(typeof(Program));
        //static List<TestCase> listTCase = new List<TestCase>();
        //static List<TestData> listTData = new List<TestData>();
        //static List<TestCommand> listTCommand = new List<TestCommand>();
        //static List<TestDataset> listTDataset = new List<TestDataset>();
        //static List<TestStep> listTStep = new List<TestStep>();
        //"D:\AutomationTest\APPLICATIONMAP\"
        //static string ExcelPath;
        static IDataAccess dtAccess = null;

        

        //Features of Automation:
        static void CmdExcuteKeyword() {
            CmdExcuteKeyword feature3 = new CmdExcuteKeyword(dtAccess);
            feature3.Main("Cmd Excute Keyword");
        }

        static void GenerateCommands() {
            bool isSuccess = false;
            do
            {
                string inDll = "";
                Console.Write("input dll file name:");
                inDll = Console.ReadLine();
                

                if (inDll.Equals("/e"))
                    break;


                inDll = ConfManager.DefaultObjectPath + inDll;
                    
                GenerateTCommandWithFile feature5 = new GenerateTCommandWithFile(inDll, dtAccess);
                isSuccess = feature5.Main("Generate TCommand with file");
            } while (!isSuccess);
        }

        static void CmdGenerateDatas() {
            CmdGenerateTData feature4 = new CmdGenerateTData(dtAccess);
            feature4.Main("Cmd Generate TestData");       
        }

        static void GenerateDatas() {
            GenerateTData feature2 = new GenerateTData(dtAccess);
            feature2.Main("Generate TestData from excel");
        }

        static void DebugTestCases() {
            DebugTCase feature1 = new DebugTCase(dtAccess);
            feature1.Main("DebugTestCases");
        }        
        
        static void BuildRelease() {
            BuildRelease feature6 = new BuildRelease(dtAccess, "Script\\");
            feature6.Main("Build Release");
        }

        static void DebugTestCasesMultithread() {
            //DebugTCase feature7 = new DebugTCase(dtAccess);
            DebugMultithread feature8 = new DebugMultithread(dtAccess);

            //feature7.Main("Debug in multithread mode");
            feature8.Main("Debug in multithread mode");
        }


        static void Refresh() {
            dtAccess.RefreshTDatas();
            log.Debug("Refresh successfull.");
        }

        static void Feature_BuildGuiMap() {
            BuildGuiMap bGuiMap = new BuildGuiMap(dtAccess, "crawlgui");
            bGuiMap.Main("Build GuiMap:");
        }
        //Features

        static void Main(string[] args)
        {



            

            //List<TestCommand> list = ComponentFunction.GetAllMethodsDLLs(@"d:\AutomationTest\APPLICATIONMAP\AppLibrary.dll");
           // ResourceManager.GetString("");
            //string ExcelPath = "test.xls";


            dtAccess = DataAccessFactory.GetDataAccess();
            
            //listTCase = dtAccess.getTestcases();
            //listTCommand = dtAccess.getTestcommands();
            //listTDataset = dtAccess.getTestdatasets();
            //listTStep = dtAccess.getTeststeps();
            //listTData = dtAccess.getTestdatas();
            ////ComponentFunction.Initialize(listTCommand);            
            //DebugTestCases();
            //GenerateDatas();
            //GenerateCommands();
            //CmdGenerateDatas();
            //CmdExcuteKeyword();
            //string processname = "YepexLite.BankingService.Console.exe";
            //string argument = "transfer";
            //ProcessClass process = new ProcessClass();
            //process.InvokeWinApp(processname, argument);


            while (true) {
                

                bool flag = true;
                log.Debug("AUTOMATION SOFTWARE V1.");
                log.Debug("1: DebugTestCases.");
                log.Debug("2: Generate TestData from excel.");
                log.Debug("3: Cmd Excute Keyword.");
                log.Debug("4: Cmd Generate TestData.");
                log.Debug("5: Generate Commands.");
                log.Debug("6: Build Release.");
                log.Debug("7: DebugTestCases in multithread mode.");
                log.Debug("8: Refresh.");
                log.Debug("9: BuildGuiMap.");
                log.Debug("/e: Exit");
                log.Debug("Your choice:");
                string input = Console.ReadLine();
                switch (input) { 
                    case "1":                       
                        DebugTestCases();                       
                        flag = false;
                        break;
                    case "2":
                        GenerateDatas();                        
                        flag = false;                        
                        break;
                    case "3":
                        CmdExcuteKeyword();                       
                        flag = false;     
                        break;
                    case "4":
                        CmdGenerateDatas();                       
                        flag = false;
                        break;
                    case "5":
                        GenerateCommands();                       
                        flag = false;
                        break;
                    case "6":
                        BuildRelease();
                        flag = false;                        
                        break;
                    case "7":
                        DebugTestCasesMultithread();
                        flag = false;
                        break;
                    case "8":
                        Refresh();
                        flag = false;
                        break;
                    case "/e":
                        flag = false;
                        break;
                    case "9":
                        Feature_BuildGuiMap();
                        flag = false;
                        break;
                }
                if (!flag)
                    break;
            }
            
            Console.ReadLine();
        }
    }
}
    
